package com.huawei.appmarket.service.usercenter.personal.view.card;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appmarket.service.usercenter.personal.view.fragment.PersonalGrid;
import java.util.ArrayList;
import java.util.List;
import o.cgz;
import o.der.d;
import o.Logger;
import o.ContentManager;
import o.epv;

public class PersonalCombineCard extends cgz {
    private PersonalGrid ˊ;
    private boolean ˎ = true;
    private List<PersonalNormalCard> ˏ = new ArrayList();
    private PersonalNormalAdapter ॱ;

    static class PersonalNormalAdapter extends BaseAdapter {
        private List<ViewGroup> viewList;

        private PersonalNormalAdapter() {
        }

        public void clear() {
            this.viewList = null;
        }

        void setViewList(List<ViewGroup> list) {
            this.viewList = list;
        }

        public int getCount() {
            return this.viewList.size();
        }

        public Object getItem(int i) {
            return this.viewList.get(i);
        }

        public long getItemId(int i) {
            return (long) i;
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            return (View) this.viewList.get(i);
        }
    }

    public PersonalCombineCard(Context context) {
        super(context);
    }

    public void ˊ(PersonalNormalCard personalNormalCard) {
        if (personalNormalCard != null) {
            this.ˏ.add(personalNormalCard);
        }
    }

    public PersonalNormalCard ˊ(int i) {
        if (i < 0 || i >= this.ˏ.size()) {
            return null;
        }
        return (PersonalNormalCard) this.ˏ.get(i);
    }

    public cgz ˏ(View view) {
        ʽ(view);
        this.ˊ = (PersonalGrid) view.findViewById(d.ꞌ);
        this.ˊ.setSelector(new ColorDrawable(0));
        this.ॱ = new PersonalNormalAdapter();
        return this;
    }

    public void ˏ(CardBean cardBean) {
        this.ॱ.clear();
        if (this.ˏ == null || this.ˏ.isEmpty()) {
            Logger.ˏ("PersonalCombineCard", "the list is empty");
            this.ˊ.setVisibility(8);
            return;
        }
        if (ˎ()) {
            this.ˊ.setNumColumns(2);
        } else {
            this.ˊ.setNumColumns(1);
        }
        this.ॱ.setViewList(ˋ(cardBean));
        this.ˊ.setAdapter(this.ॱ);
    }

    private List<ViewGroup> ˋ(CardBean cardBean) {
        List<ViewGroup> arrayList = new ArrayList();
        int i = 0;
        while (i < this.ˏ.size()) {
            ((PersonalNormalCard) this.ˏ.get(i)).ˏ(cardBean);
            PersonalNormalCard ˊ = ˊ(i);
            if (ˊ != null) {
                ˊ.ˉ().setVisibility(0);
                arrayList.add((ViewGroup) ˊ.ˉ());
                ˊ.ˏ(true);
                if (!this.ˎ && i >= ˋ()) {
                    ˊ.ˏ(false);
                }
            }
            i++;
        }
        return arrayList;
    }

    private boolean ˎ() {
        return epv.ˏॱ(ContentManager.getInstant().getContext());
    }

    private int ˋ() {
        int size = this.ˏ.size() - 1;
        if (ˎ() && this.ˏ.size() % 2 == 0) {
            return size - 1;
        }
        return size;
    }

    public void ˊ(boolean z) {
        this.ˎ = z;
    }
}
